import Axios from 'axios'; //引入axios
import qs from 'qs';	//引入axios数据处理
import Public from './public.js' //加载公用js方法文件
Axios.defaults.timeout = 10000;
//Axios.defaults.headers.post['Content-Type'] = '';   //配置请求头
// axios.defaults.baseURL = 'http://spsj.xn62x.cn';   //配置接口地址
// axios.defaults.baseURL = 'http://192.168.1.100';   //配置接口地址
//Axios.defaults.headers.common['token'] = token;
//Axios.defaults.headers.common['account'] = account;

// 添加一个响应拦截器
Axios.interceptors.request.use((config) => {
	let account =  sessionStorage.account;
	let token = sessionStorage.token;
	config.headers['token'] = token;
	config.headers['account'] = account;
  //在发送请求之前做某件事
  // 判断是否登录
  	// let cur_id = "cur_id",
  	// 	  sign = "sign";
   //  if (!cur_id||!sign) {
   //    localStorage.clear();
   //    window.location.href = "index.html";
   //  };
    if(config.method  === 'post'){
        config.data = qs.stringify(config.data);
        config.data = config.data+"&account=" + account;
    }
    if(config.method  === 'get'){
      config.params.account = account;
    }
    return config;
},(error) =>{
     _.toast("错误的传参", 'fail');
    return Promise.reject(error);
});

// 添加返回信息验证
Axios.interceptors.response.use(function (response) {
    if(response.data.status =='505' || response.data.status =='404'){
    	if(!sessionStorage.account){
    		return false;
    	}
      sessionStorage.clear();
//    alert(response.data.msg);
    	window.location.href = "/#/login";
    };
    return response;
  }, function (error) {
    return Promise.reject(error);
  });
  
// 网络地址
//let base = 'http://192.168.1.4/55coin/php';
//let ifno = "http://47.52.135.227:8080";
//let second = "";
// let second = 'http://' + window.location.host;
let second = 'http://zgxxcl.com';
// let Mainwsurl = "ws://" + window.location.host + ":7272";
// let Secondwsurl = "ws://" + window.location.host;
//http://zgxxcl.com
let Mainwsurl = "ws://zgxxcl.com:7272";
let Secondwsurl = "ws://zgxxcl.com";
// 接口地址

Axios.bases = `${second}/`;
Axios.getNewInfo = `${second}/sexp/stock/getNewInfo`;
Axios.send_sms = `${second}/home/qbw/send_sms`;  //短信验证码  1注册 2 重置 3 安全验证 4 支付密码设置 5 提币 mobile ,type
Axios.register = `${second}/home/qbw/register`;  //注册
Axios.user_login = `${second}/home/qbw/user_login`; //登录  mobile	opwd	verify
Axios.auth_code = `${second}/home/qbw/auth_code`; //图片验证码
Axios.reset_opwd = `${second}/home/qbw/reset_opwd`; //找回密码   mobile opwd	opwd1	code
Axios.link = `${second}/home/qbw/link`;  //推广海报  account 

Axios.helpCenter = `${second}/home/qbw/FAQ`;  //帮助中心
Axios.articleList = `${second}/home/qbw/get_more`;  // 文章列表
Axios.articleDetails = `${second}/home/qbw/get_detail`;  // 文章详情
Axios.sellRequest = `${second}/home/qbw/u_msg`;  // 提交请求
Axios.searchData = `${second}/home/qbw/search`;  // 搜索
Axios.ziChan = `${second}/home/api/asset`;  // 资产
Axios.caiWu = `${second}/home/qbw/caiwu`;  // 财务记录
Axios.moneyDeal = `${second}/home/qbw/record`;  // 充币提币-type,cash/recharge,默认recharge
Axios.addrList = `${second}/home/qbw/AddrList`;  // 提币地址列表
Axios.deltAddre = `${second}/home/qbw/AddrManage`;  // 添加、删除提币地址
Axios.goPay = `${second}/index.php/home/order/bpay`;  // 账户充值 
Axios.goBit = `${second}/Home/Order/ti_bi`;  // 账户提币
// Axios.weiTuo = `${second}/home/order/weituo`;  // 委托
Axios.zixunList = `${second}/home/qbw/zixun`;  // BFEX资讯列表
Axios.zixunDetails = `${second}/home/qbw/zixun_detail`;  // BFEX资讯详情
Axios.fbOrder = `${second}/home/qbw/getFbMx`;  // 法币交易->订单
Axios.get_lever = `${second}/home/api/get_lever`;  // 杠杆交易获取杠杆信息
Axios.getFbMx_pmma = `${second}/home/qbw/getFbMx_pmma`;  // 法币交易->购买
Axios.getFbMx_sell = `${second}/home/qbw/getFbMx_sell`;  // 法币交易->出售
// Axios.bbOrder = `${second}/index.php/Home/Trade/tranlist`;  // 币币交易->订单
Axios.dealCancel = `${second}/index.php/Home/Trade/cancel`;  // 币币交易->撤单
Axios.getPro = `${second}/index.php/Home/Trade/get_pro`;  // 获取币种信息
Axios.agreeMent = `${second}/home/qbw/agree`;  // 获取协议信息(协议、条款、说明)
Axios.create_order = `${second}/home/Fbtrans/create_order`;  // 法币交易下单
Axios.orderDetail = `${second}/home/Fbtrans/orderDetail`;  // 法币订单买方详细
Axios.MyorderDetail = `${second}/home/qbw/MyorderDetail`;  // 法币订单卖方详细
Axios.setOrderStatus = `${second}/home/Fbtrans/setOrderStatus`;  // 标记已付款
Axios.post_allege = `${second}/home/Fbtrans/post_allege`;  // 提交申诉
Axios.re_order = `${second}/home/Fbtrans/re_order`;  // 法币取消订单
Axios.add_order = `${second}/index.php/Home/Order/add_order`;  // 杠杆交易下单
Axios.cancellations = `${second}/index.php/Home/Order/cancellations`;  // 杠杆交易-订单-委托撤销
Axios.pingcang = `${second}/index.php/Home/Order/pingcang`;  // 杠杆交易-订单-手动平仓
Axios.chengjiao = `${second}/index.php/Home/Order/chengjiao`;  // 杠杆交易-订单-成交记录
Axios.weituo = `${second}/index.php/Home/Order/weituo`;  // 杠杆交易-订单-委托记录
Axios.chicang = `${second}/index.php/Home/Order/chicang`;  // 杠杆交易-订单-持仓记录  
Axios.publicData = `${second}/home/qbw/public_data`;  // footer邮箱地址
Axios.set_poit = `${second}/Home/Order/set_poit`;  //设置止盈止损
Axios.transfer = `${second}/Home/Users/Transfer`;  //站内转账
Axios.get_balance = `${second}/Home/Users/get_balance`;  //查看余额
Axios.Record_Transfer = `${second}/Home/Users/Record_Transfer`; //转账流水
Axios.all_ping = `${second}/Home/Order/all_ping`;
Axios.tongji = `${second}/Home/Order/tongji`;  //订单信息统计

//Fbtrans
Axios.user_info = `${second}/home/qbw/user_info`;  //个人中心接口
Axios.xiugai_pwd = `${second}/home/qbw/xiugai_pwd`;  //修改登录密码 account	oldpwd	opwd	opwd1
Axios.binding_email = `${second}/home/qbw/binding_email`;  //绑定邮箱
Axios.binding_mobile = `${second}/home/qbw/binding_mobile`;  //设置手机号
Axios.reset_tpwd = `${second}/home/qbw/reset_tpwd`;  //修改资金密码
Axios.user_aq = `${second}/home/qbw/user_aq`;   //登录历史安全历史接口

Axios.MainwsUrl = `${Mainwsurl}`;
Axios.SecondwsUrl = `${Secondwsurl}:7272/`;   //创新区长链接
Axios.SecondSalewsUrl = `${Secondwsurl}:7273/`;   //创新区长链接
Axios.getNewInfo = `${second}/home/Ajax/getpro`;   //五大币API
Axios.crowd = `${second}/home/api/crowd`;   //创新币种API
Axios.trading = `${second}/home/Fbtrans/trading`;   //出售/购买广告
Axios.get_info = `${second}/home/qbw/get_info`;   //币种信息
Axios.tranlist = `${second}/index.php/Home/Trade/tranlist`;   //币币交易记录
Axios.bbtran = `${second}/index.php/Home/Trade/bbtran`;   //币币交易
Axios.xinxi = `${second}/index.php/home/Trade/xinxi`;   //获取个人币种资产

Axios.pay_list = `${second}/home/Fbtrans/pay_list`;   //支付方式列表
Axios.pay_edit = `${second}/home/qbw/pay_edit`;   //支付方式编辑页数据
Axios.pay_add = `${second}/home/qbw/pay_add`;   //添加/编辑提交 支付方式
Axios.set_pay_status = `${second}/home/qbw/set_pay_status`;   //改变支付方式状态
Axios.upload = `${second}/upload.php`;   //图片上传
Axios.set_sm = `${second}/home/qbw/set_sm`;   //设置实名
Axios.set_img = `${second}/home/qbw/set_img`;   //高级认证
Axios.add_shop = `${second}/home/Fbtrans/add_shop`;   //成为商家
Axios.pmma = `${second}/home/Fbtrans/pmma`;   //求购/出售 发单
Axios.pmmaList = `${second}/home/Fbtrans/pmmaList`;   //求购/售出 列表
Axios.pmmaRev = `${second}/home/Fbtrans/pmmaRev`;   //求购/售出 撤单
Axios.cat_shopinfo = `${second}/home/Fbtrans/cat_shopinfo`; //查看商家信息
Axios.agree = `${second}/home/qbw/agree`;  //用户协议
Axios.confirm = `${second}/home/Fbtrans/confirm`; //确认放行
Axios.del_shop = `${second}/Home/Fbtrans/del_shop` ;  //取消商家
Axios.bk_list = `${second}/home/Broker/bk_list` ;  //经纪人信息
Axios.bk_applay = `${second}/Home/Broker/bk_apply`; //经纪人申请
Axios.bk_info = `${second}/Home/Broker/bk_info`; //经纪人申请
Axios.get_price = `${second}/Home/Fbtrans/get_price`; //获得价格
Axios.re_asset = `${second}/Home/qbw/re_asset`; //个人流水
Axios.get_tb = `${second}/Home/api/get_tb`; // 提币限制条件

//基金接口
Axios.index = `${second}/home/Fund/index`;  //头部数据
Axios.fundlist = `${second}/home/Fund/fundlist`; //主页及分红页面
Axios.bflist = `${second}/home/Fund/bflist`; // 资金明细
Axios.mininglist = `${second}/home/Fund/mininglist`; // 挖矿明细



// 众筹
Axios.recindex = `${second}/Home/Recognize/recindex`; // 众筹列表
Axios.dorec = `${second}/Home/Recognize/dorec`; // 认筹提交
Axios.reclist = `${second}/Home/Recognize/reclist`; // 众筹列表

Axios.transform = `${second}/home/Fund/transform`; // 余额划转
//底部信息接口
Axios.public_data = `${second}/home/qbw/public_data`;
Axios.agree = `${second}/home/qbw/agree`;
Axios.createGoogleCommand = `${second}/home/google/createGoogleCommand`;//开启谷歌身份验证
Axios.setGoogleMsg = `${second}/home/google/setGoogleMsg`;//谷歌身份验证短信验证码
Axios.checkGoogleCommand = `${second}/home/google/checkGoogleCommand`;//绑定谷歌验证
//币种兑换接口

Axios.thisCoinList = `${second}/home/exchange/thisCoinList`;  //查询交易单据状态接口
Axios.exchange = `${second}/home/exchange/exchange`;  //兑换
Axios.ex_list = `${second}/home/Exchange/ex_list`;//兑换列表

export default Axios;

// Fbtrans
/*
 * 复制专用
 _this.$http.post(_this.$http.user_info, {}).then(function(response) {
				if(response.data.status == "200") {
				} else {
					_this.$public.msg(response.data.msg, 'warning', _this);
				}
			}).catch(function(error) {});
 * 
 * 
 * 
 * 
 * */
